﻿using System;
using System.Globalization;

namespace SpeadFrm.Utility
{
    public static class DateTimeHelper
    {
        public static DateTime GetWeekMonday(DateTime dateTime)
        {
            var firstDate = DateTime.Now;
            switch (dateTime.DayOfWeek)
            {
                case System.DayOfWeek.Monday:
                    firstDate = dateTime;
                    break;
                case System.DayOfWeek.Tuesday:
                    firstDate = dateTime.AddDays(-1);
                    break;
                case System.DayOfWeek.Wednesday:
                    firstDate = dateTime.AddDays(-2);
                    break;
                case System.DayOfWeek.Thursday:
                    firstDate = dateTime.AddDays(-3);
                    break;
                case System.DayOfWeek.Friday:
                    firstDate = dateTime.AddDays(-4);
                    break;
                case System.DayOfWeek.Saturday:
                    firstDate = dateTime.AddDays(-5);
                    break;
                case System.DayOfWeek.Sunday:
                    firstDate = dateTime.AddDays(-6);
                    break;
            }
            return Convert.ToDateTime(firstDate.ToShortDateString());
        }

        public static DateTime GetWeenSunday(DateTime datetime)
        {
            var lastDate = DateTime.Now;
            switch (datetime.DayOfWeek)
            {
                case System.DayOfWeek.Monday:
                    lastDate = datetime.AddDays(6);
                    break;
                case System.DayOfWeek.Tuesday:
                    lastDate = datetime.AddDays(5);
                    break;
                case System.DayOfWeek.Wednesday:
                    lastDate = datetime.AddDays(4);
                    break;
                case System.DayOfWeek.Thursday:
                    lastDate = datetime.AddDays(3);
                    break;
                case System.DayOfWeek.Friday:
                    lastDate = datetime.AddDays(2);
                    break;
                case System.DayOfWeek.Saturday:
                    lastDate = datetime.AddDays(1);
                    break;
                case System.DayOfWeek.Sunday:
                    lastDate = datetime;
                    break;
            }
            return Convert.ToDateTime(lastDate.ToShortDateString());
        }
    }
}